/**
* Created by yyr on 2018/1/10
*已设立基金》详情页
*/
<template>
    <div>
        <div class="right">
            <el-row>
                <el-col :span="24" class="ca-align-right">
                    <div class="ca-head-fixed">
                        <el-button type="primary" @click="preInvesting()" :disabled="!(this.fundAnsatEstList.length > 0)" v-if="FOF">拟投资信息</el-button>
                        <el-button type="primary" @click="preInvesting()" :disabled="!(this.fundAnsatEstList.length > 0)" v-else>拟设立信息</el-button>
                        <el-button type="primary" @click="toExitFund()" :disabled="disableBtn">一键转已到期</el-button>
                    </div>
                </el-col>
            </el-row>
            <!--头部详情-->
            <div class="ca-m-t-28">
                <csFundHead @addRedDot="addRedDot" ref="headRef"></csFundHead>
            </div>
            <el-tabs type="border-card" class="ca-tabs ca-m-t-15" @tab-click="handleClick" :value="tabIndex">
                <el-tab-pane :label="tabArr[0]" :disabled="!isAuthFundDetail">
                    <csRedDot slot="label" :label="tabArr[0]" :showDot="dotStateList[0]"></csRedDot>
                    <div v-if="activeIndex == 0">
                        <!--基本信息-->
                        <csFundDetailsBasic @addRedDot="addRedDot"></csFundDetailsBasic>
                        <!--管理机构信息-->
                        <div class="ca-m-t-20">
                            <csFundDetailsManageOrgan @addRedDot="addRedDot"></csFundDetailsManageOrgan>
                        </div>
                        <!--管理层-->
                        <csFundDetailsManage @addRedDot="addRedDot"></csFundDetailsManage>
                        <!--账户信息-->
                        <csFundAccount @addRedDot="addRedDot"></csFundAccount>
                    </div>
                </el-tab-pane>
                <!--合伙人认缴-->
                <el-tab-pane :label="tabArr[1]" :disabled="!isAuthPartnerSee">
                    <csRedDot slot="label" :label="tabArr[1]" :showDot="dotStateList[1]"></csRedDot>
                    <div v-if="activeIndex == 1">
                        <csFundDetailsPartner @addRedDot="addRedDot" @refresh="refreshPage"></csFundDetailsPartner>
                    </div>
                </el-tab-pane>
                <!--管理费核定-->
                <el-tab-pane :label="tabArr[2]" :disabled="!isAuthManageSee">
                    <csRedDot slot="label" :label="tabArr[2]" :showDot="dotStateList[2]"></csRedDot>
                    <div v-if="activeIndex == 2">
                        <csManagementAssessment @addRedDot="addRedDot"></csManagementAssessment>
                    </div>
                </el-tab-pane>
                <!--投资数据-->
                <el-tab-pane :label="tabArr[3]" :disabled="!isAuthInvestedSee">
                    <csRedDot slot="label" :label="tabArr[3]" :showDot="dotStateList[3]"></csRedDot>
                    <div v-if="activeIndex == 3">
                        <csFundDetailsInvestment></csFundDetailsInvestment>
                    </div>
                </el-tab-pane>
                <!--基金分配-->
                <el-tab-pane :label="tabArr[4]" :disabled="!isAuthDistributionSee">
                    <csRedDot slot="label" :label="tabArr[4]" :showDot="dotStateList[4]"></csRedDot>
                    <div v-if="activeIndex == 4">
                        <csFundDetailsDistribution @addRedDot="addRedDot"></csFundDetailsDistribution>
                    </div>
                </el-tab-pane>
                <!--基金文档-->
                <el-tab-pane :label="tabArr[5]" :disabled="!isAuthFileSee">
                    <csRedDot slot="label" :label="tabArr[5]" :showDot="dotStateList[5]"></csRedDot>
                    <div v-if="activeIndex == 5">
                        <csFundFileDetail
                            title="基金文档"
                            :businessId="itemId"
                            :fileType="fileType"
                            :addAuth="authText"
                            @addDot="addRedDot(5)"
                        ></csFundFileDetail>
                    </div>
                </el-tab-pane>
                <!--管理记录-->
                <el-tab-pane :label="tabArr[6]" :disabled="!isAuthRecordSee">
                    <csRedDot slot="label" :label="tabArr[6]" :showDot="dotStateList[6]"></csRedDot>
                    <div v-if="activeIndex == 6">
                        <csFundManagementRecord @addRedDot="addRedDot"></csFundManagementRecord>
                    </div>
                </el-tab-pane>
                <!--重大事项审批-->
                <el-tab-pane :label="tabArr[7]" :disabled="!isAuthApproveSee">
                    <csRedDot slot="label" :label="tabArr[7]" :showDot="dotStateList[7]"></csRedDot>
                    <div v-if="activeIndex == 7">
                        <csApprovalProcess></csApprovalProcess>
                    </div>
                </el-tab-pane>
                <!--基金支出-->
                <el-tab-pane :label="tabArr[8]" :disabled="!isAuthExpendSee">
                    <csRedDot slot="label" :label="tabArr[8]" :showDot="dotStateList[8]"></csRedDot>
                    <div v-if="activeIndex == 8">
                        <csFundExpenditure @addRedDot="addRedDot"></csFundExpenditure>
                    </div>
                </el-tab-pane>
                <!--闲散理财-->
                <el-tab-pane :label="tabArr[9]" :disabled="!isAuthIdleSee">
                    <csRedDot slot="label" :label="tabArr[9]" :showDot="dotStateList[9]"></csRedDot>
                    <div v-if="activeIndex == 9">
                        <csFundIdleMoney @addRedDot="addRedDot"></csFundIdleMoney>
                    </div>
                </el-tab-pane>
            </el-tabs>
        </div>
    </div>
</template>

<script type="text/ecmascript-6">
    import {api} from './api';
    import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp';
    import {addRemind, getDetailRemind, isNoAuth, read} from '__service/utils';
    export default {
        data() {
            return {
                isAuthFundDetail: isNoAuth('已投资基金-基金详情-查看'),
                isAuthPartnerSee: isNoAuth('已投资基金-合伙人认缴-查看'),
                isAuthManageSee: isNoAuth('已投资基金-管理费核定-查看'),
                isAuthInvestedSee: isNoAuth('已投资基金-投资数据-查看'),
                isAuthDistributionSee: isNoAuth('已投资基金-基金分配-查看'),
                isAuthRecordSee: isNoAuth('已投资基金-管理记录-查看'),
                isAuthApproveSee: isNoAuth('已投资基金-重大事项审批-查看'),
                isAuthFileSee: isNoAuth('已投资基金-基金文档-查看'),
                isAuthExpendSee: isNoAuth('已投资基金-基金支出-查看'),
                isAuthIdleSee: isNoAuth('已投资基金-闲散理财-查看'),
                tabArr: ['基金详情', '合伙人认缴', '管理费核定', '投资数据', '基金分配', '基金文档', '管理记录', '重大事项审批', '基金支出', '闲散理财'],
                tabIndex: this.$route.params.tabIndex.toString(),
                 itemId: this.$route.params.fundId,
                fileType: '10011',
                authText: '已投资基金-基金文档-编辑',
                activeIndex: 0,
                dotStateList: [false, false, false, false, false, false, false], // 小红点状态
                query: {},//存放头部详情的对象
                fundAnsatEstList: [],//设立前基金
                disableBtn: false, // 禁用一键转已到期
            }
        },
        watch: {
        },
        props: {},
        beforeRouteEnter(to, from, next) {
            next( vm => {
                if (!isNoAuth('已投资基金-' + vm.tabArr[vm.tabIndex] + '-查看')) {
                    let flag = false;
                    for (let i = vm.tabIndex; i < vm.tabArr.length; i++) {
                        if (isNoAuth('已投资基金-' + vm.tabArr[i] + '-查看')) {
                            vm.tabIndex = i.toString();
                            flag = true;
                            break;
                        }
                    }
                    if (!flag) {
                        for (let i = 0; i < vm.tabIndex; i++) {
                            if (isNoAuth('已投资基金-' + vm.tabArr[i] + '-查看')) {
                                vm.tabIndex = i.toString();
                                flag = true;
                                break;
                            }
                        }
                    }
                    if (!flag) {
                        vm.$message({
                            message: '没有此页面的操作权限',
                            type: 'error',
                            center: true
                        });
                        vm.$router.replace({name: 'personal-center', params: {tabIndex: '0', openWindow: false}})
                    }
                }
            })
        },
        created() {
            this.init();
            if (this.$route.params.isExit) {
                this.disableBtn = true;
            }
        },
        mounted() {
            let ind = {
                index: this.$route.params.tabIndex.toString()
            }
            this.handleClick(ind)
//            // 获取红点
            this.getDotList();
            // 为子组件创建的第三方组件方法
            this.$root.Dot.$on('getDotList', () => {
                this.getDotList();
            })
        },
        methods: {
            //拟投资信息
            preInvesting() {
                this.$router.push({name: 'pre-investment-funds', params: {itemId: this.fundAnsatEstList[0].ansatId, tabIndex: 0, openWindow: true}})
            },
            // 设置小红点状态
            async getDotList() {
                const dotList = await getDetailRemind({ dataId: this.$route.params.fundId, dataType: 5 });
                dotList.map(x => {
                    this.dotStateList[x.dataTab] = true;
                });
                this.dotStateList = this.dotStateList.concat([]);
            },
            // 切换tab
            handleClick(val) {
                this.activeIndex = val.index;
                //去除小红点
                read({ dataId: this.$route.params.fundId, dataTab: val.index, dataType: 5 });
                this.dotStateList[val.index] = false;
                this.dotStvalateList = this.dotStateList.concat([]);
                // 设置小红点状态 end
            },
            async addRedDot(index) {
                // 添加小红点
                await addRemind({
                    dataId: this.$route.params.fundId, // 业务id
                    dataTab: index, // tab页顺序 head 也为0 新建为'-1'
                    dataType: 5, // 1拟投资项目,2已投资项目,3母基金,4拟设立基金,5已设立基金,6客户,7潜在项目
                });
                // 根据第三方组件来调用 父组件中定义的方法 重新获取小红点
                this.$root.Dot.$emit('getDotList');
                // 添加小红点 end
            },
            init() {
                apiHttp(api.HEAD_DETAIL,{fundId: this.itemId}).then( ret=>{
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        if (ret.data.fundAnsatEstList.length > 0) {
                            this.fundAnsatEstList = ret.data.fundAnsatEstList;
                        }
                        this.query = Object.assign({},{
                            fund: ret.data.fund,
                            fundAnsatEstList: ret.data.fundAnsatEstList,
                            industryList: ret.data.industryList,
                            fundUserList: ret.data.fundUserList
                        })
                    }
                })
            },
            //转已到期
            toExitFund() {
                this.init();
                this.$confirm('是否转成已到期基金?', '提示', {
                    cancelButtonText: '取消',
                    confirmButtonText: '确定',
                    type: 'warning',
                    showClose: false
                }).then(async () => {
                    this.query.fund.fundState = 3;
                    apiHttp(api.HEAD_CHANGE, this.query).then( ret1 => {
                        if (ret1.resCode === STATUS_HTTP_SUCCESS) {
                            this.$message({
                                type: 'success',
                                message: '操作成功!',
                                center: true
                            });
                            this.$router.push({name: 'exit-funds-list'})
                        }
                    })
                })
            },
            // 刷新页面
            refreshPage() {
                this.$refs.headRef.getHeadDetail();
            }
        },
        beforeDestroy() {
            // 销毁小红点第三方vue
            this.$root.Dot.$off('getDotList');
        },
        components: {
            'csFundHead': require('./header/index.vue'),//头部index页
            'csFundDetailsBasic': require('./basic/index.vue'), //基本信息
            'csFundDetailsManageOrgan': require('./management-org/index.vue'), //管理机构
            'csFundDetailsManage': require('./management/index.vue'), //管理层
            'csFundAccount': require('./account/index'), //选项卡基本信息》账户信息 index
            'csManagementAssessment': require('./management-assessment/index.vue'), //管理费核定 [2]
            'csFundDetailsPartner': require('./partner-paid/index.vue'), //选项卡基本信息》合伙人信息 index
            'csFundExpenditure': require('./fund-expenditure/index.vue'),//选项卡基本信息》基金支出 index
            'csFundDetailsInvestment': require('./investment/index.vue'),//选项卡基金信息》投资数据 index
            'csFundManagementRecord': require('./management-record/index.vue'),//管理记录
            'csFundDetailsDistribution': require('./fund-distribution/index.vue'),//选项卡基金信息》基金分配 index
            'csFundIdleMoney': require('./idle-money/index.vue'),//选项卡基金信息》闲散理财 index
            'csFundFileDetail': require('__components/file-list/index'),//选项卡基金信息》文件管理
            'csApprovalProcess': require('./approval-process/index.vue'),//选项卡》重大事件审批
            'csRedDot': require('__components/red-dot'), // 小红点
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>

</style>
